<!DOCTYPE html>
<html>
<head>
{{template "common_header.html" .}}
    <style>
        #role-form-left{
            width:500px;
            display:inline-block;
            float:left;
        }
        #role-form-right{
            width:500px;
            display:inline-block;
            float:left;
        }
    </style>
</head>
<body>
<div class="x-body">
    <form class="layui-form" method="post" onsubmit="return false;" id="doc-add-role-form">
        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="角色名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色描述</label>
            <div class="layui-input-block">
                <input type="text" name="desc" placeholder="角色描述" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">生效APP</label>
            <div class="layui-input-block">
                <select name="app_id" lay-filter="role-app-select">
                    <option value="">选择APP</option>
                    {{range $index, $item := .appList}}
                        <option value="{{$item.id}}">{{$item.app_name}}</option>
                    {{end}}
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="margin-top:50px;">
            <button class="layui-btn layui-btn-normal" id="submit-btn" style="width:100%;">保存</button>
        </div>
    </form>
</div>
{{template "common_js.html" .}}
<script>
    layui.use('element', function(){
        var element = layui.element;
    });

    $(function(){
        $("#submit-btn").click(function () {
            var data = $("#doc-add-role-form").serialize();
            var url = "/doAddRole";
            $.post(url, data, function (resp) {
                if(resp.en == 200) {
                    layer.msg(resp.em);
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                    parent.location.reload();
                } else {
                    layer.msg(resp.em);
                }
            });
        });

    });
</script>
</body>
</html>